<?php
/*
 * Пример
 *        $Sections = new SectionsModel('modul_id',9);
 *        $data = $Sections -> getData();
 */
class SectionsModel extends BDModel {

    function __construct($column = null, $value = null){

        $this->table = "sections";

        parent::__construct($column, $value);

    }


    /*
    * @func   : Возвращает section_id
    * @params : section_seo_name
    * @returns: false
    *
    */
    function getSectionIdByName($name){

        $id = null;

        $name_lower = strtolower($name);

        $name_spaceless = preg_replace('/_/','',$name);
        $name_lower_spaceless = preg_replace('/_/','',$name_lower);

        $q = "SELECT * FROM   `sections`
              WHERE seo_link = '$name' OR title = '$name'
                    OR seo_link = '$name_lower' OR title = '$name_lower'
                    OR seo_link_translited = '$name' OR  seo_link_translited = '$name_lower'
                    OR seo_link = '$name_spaceless' OR title = '$name_spaceless' OR seo_link_translited = '$name_spaceless'
                    OR seo_link = '$name_lower_spaceless' OR title = '$name_lower_spaceless' OR seo_link_translited = '$name_lower_spaceless'
                    ";

        $this->Sql($q);
        $this->Select();

        $data = $this->getData();

        if(isset($data[0]['sm_id'])) $id = $data[0]['sm_id'];

        return $id;
    }
}
